package com.wyh.order.controller;

import com.wyh.order.model.DO.OrderInfo;
import com.wyh.order.model.DO.ProductInfo;
import com.wyh.order.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("order")
public class OrderInfoController {
    @Autowired
    OrderInfoService orderInfoService;

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping("/{orderId}")
    public OrderInfo selectOrderById(@PathVariable("orderId") Integer orderId){
        OrderInfo orderInfo = orderInfoService.selectOrderById(orderId);
        String url = "http://127.0.0.1:8082/product/" + orderInfo.getProductId();
        ProductInfo forObject = restTemplate.getForObject(url, ProductInfo.class);
        orderInfo.setProductInfo(forObject);
        return orderInfo;
    }
}
